#include "messagecontroller.h"

#include <sstream>

#include "view.h"

using namespace fortress;

messageController & messageController::getInstance()
{
	static messageController instance;
	return instance;
}

messageController::messageController()
{
	screen=0;
}

messageController::~messageController()
{

}

void messageController::setView(view * viewObject)
{
	screen = viewObject;
}

bool messageController::displayMessages()
{
	if (messageQueue.size()==0)
		return false;
	screen->printMessage(*messageQueue.front());
	std::string * temp = messageQueue.front();
	messageQueue.pop();
	delete temp;
	return (messageQueue.size() != 0);
}

messageController const & messageController::addMessage(std::string const & message)
{
	std::string * temp = new std::string(message);
	messageQueue.push(temp);
	test = temp;
	return *this;
}

messageController const & messageController::error(std::string const & message) const
{
	screen->printError(message);
	return *this;
}

messageController const & messageController::debug(std::string const & message) const
{
	screen->printDebug(message);
	return *this;
}

messageController const & messageController::debug(int message) const
{
	std::stringstream s;
	s << message;
	screen->printDebug(s.str());
	return *this;
}